<?php
require_once 'models/models_quangcao.php';
$mod = $_GET['mod'];
$obqc = new models_quangcao();	
switch ($mod){
	case 'quangcao':{
		$data['list'] = $obqc->_listquangcao();
		//echo var_dump($data);
		require_once 'views/admin/quangcao/index.php';
		break;
	}
	case 'addquangcao':{
		if($_POST){
		if (isset($_FILES))
					{
						move_uploaded_file($_FILES['hinh']['tmp_name'], 'public/images/'.$_FILES['hinh']['name']);
						$Hinh = $_FILES['hinh']['name'];
					}
       $obqc->_addquangcao($_POST['ten'],$Hinh,$_POST['url'],$_POST['vitri'], $_POST['anhien']);
			echo '<script> window.location.href="admin.php?mod=quangcao"</script>';
		}
		require 'views/admin/quangcao/add.php';
		break;
	}
	case 'delquangcao':{
		$obqc->_delquangcao($_GET['ma']);
		echo '<script>window.location.href="admin.php?mod=quangcao"</script>';
		break;
	}
	case 'updatequangcao':{
		if($_POST){
		if (isset($_FILES))
					{
						move_uploaded_file($_FILES['hinh']['tmp_name'], 'public/images/'.$_FILES['hinh']['name']);
						$Hinh = $_FILES['hinh']['name'];
					}
			$obqc->_updatequangcao($_POST['ten'],$Hinh,$_POST['url'],$_POST['vitri'],$_POST['anhien'], $_GET['ma']);
			echo '<script>window.location.href="admin.php?mod=quangcao"</script>';
		}
		$data = $obqc->_getquangcao($_GET['ma']);
		require 'views/admin/quangcao/edit.php';
		break;
	}
	default: {echo  'Yêu cầu chưa được xử lý !'; break;}
	}
?>